package com.mia.props.network;

import com.mia.props.Props;
import com.mia.props.common.TileProps;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;

public class Msg0x00SwitchRunning implements IMessage {
   private boolean status;
   private int dim;
   private int x;
   private int y;
   private int z;

   public Msg0x00SwitchRunning() {
   }

   public Msg0x00SwitchRunning(TileProps props) {
      this.status = props.getIsRunning();
      this.dim = props.getWorldObj().provider.dimensionId;
      this.x = props.xCoord;
      this.y = props.yCoord;
      this.z = props.zCoord;
   }

   public void fromBytes(ByteBuf buf) {
      this.dim = buf.readInt();
      this.x = buf.readInt();
      this.y = buf.readInt();
      this.z = buf.readInt();
      this.status = buf.readBoolean();
   }

   public void toBytes(ByteBuf buf) {
      buf.writeInt(this.dim);
      buf.writeInt(this.x);
      buf.writeInt(this.y);
      buf.writeInt(this.z);
      buf.writeBoolean(this.status);
   }

   public static class Handler<T extends Msg0x00SwitchRunning> implements IMessageHandler<T, Msg0x00SwitchRunning> {
      public Msg0x00SwitchRunning onMessage(T msg, MessageContext ctx) {
         Msg0x00SwitchRunning message = (Msg0x00SwitchRunning)msg;
         Props.proxy.runningTEStateUpdate(message.dim, message.x, message.y, message.z, message.status);
         return null;
      }
   }
}
